<!--
 * @Description: 我的购物车页面组件
 * @Author: hai-27
 * @Date: 2020-02-20 01:55:47
 * @LastEditors: hai-27
 * @LastEditTime: 2020-02-27 13:36:42
 -->

<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
      <el-breadcrumb-item :to="{ path: '/' }">
        <i class="el-icon-s-promotion"></i> 首页
      </el-breadcrumb-item>
      <el-breadcrumb-item>购物车</el-breadcrumb-item>
    </el-breadcrumb>

    <el-divider></el-divider>

    <el-table :data="carts" border style="width: 100%">
      <el-table-column prop="phoneName" label="手机名称" width="300" align="center"></el-table-column>
      <el-table-column label="手机图片" width="500"  align="center">
        <template slot-scope="scope">
          <!--scope里面装着这一行所对应的对象信息,scope.$index得到下标
          scope.row得到这一行对应数组里面的图片路径-->
          <img :src="require('D:/files/'+scope.row.phoneUrl)" width="100%" height="300px" alt="">
        </template>
      </el-table-column>
      <el-table-column prop="phoneVersion" label="手机配置" width="200" align="center"></el-table-column>
      <el-table-column prop="totalPrice" label="价格" width="200" align="center"></el-table-column>
      <el-table-column prop="num" label="数量" width="200" align="center"></el-table-column>

      <el-table-column label="操作" width="300" align="center">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" size="mini" circle
                     @click="handleEdit(scope.row.id)"></el-button>
          <el-button type="danger" icon="el-icon-delete" size="mini" circle
                     @click="openDeleteConfirm(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapActions } from "vuex";
import { mapGetters } from "vuex";

export default {
  data() {
    return {
      carts:[]
    };
  },
  methods: {
    loadCartList(){
      console.log('准备从服务器端加载【订单列表】……');
      let username =this.qs.parse(localStorage.getItem('username'));

      console.log(username);
      let url = 'http://localhost:9081/carts?username=';

      console.log('请求路径：' + url);
      this.axios
          .get(url+"1234")
          .then((response) => {
            let responseBody = response.data;
            console.log('接收到服务器端响应的结果：');
            console.log(responseBody);
            this.carts = responseBody.data;
          });
    }
  },
  mounted(){
    this.loadCartList();
  }
};
</script>
<style scoped>
body{
  background-color: white;
}
</style>